﻿using System.IO;

namespace Jil.Common
{
	internal class PeekSupportingTextReader : TextReader
	{
		private TextReader Inner;

		private int? Peeked;

		public PeekSupportingTextReader(TextReader inner)
		{
			Inner = inner;
		}

		public override int Peek()
		{
			if (Peeked != null) return Peeked.Value;

			Peeked = Inner.Read();

			return Peeked.Value;
		}

		public override int Read()
		{
			if (Peeked != null)
			{
				var ret = Peeked.Value;
				Peeked = null;

				return ret;
			}

			return Inner.Read();
		}
	}
}